package com.cy.law.vo;


import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.data.domain.Page;

@Data
@AllArgsConstructor
public class PageInfo {
    private int currentRecord;
    private int currentPage;
    private int numPerPage;
    private long totalRecord;
    private long totalPage;


    public PageInfo() {
    }

    public static PageInfo Page2PageInfo(Page pageObject) {
        PageInfo pageInfo = new PageInfo();
        pageInfo.setNumPerPage(pageObject.getPageable().getPageSize());
        pageInfo.setCurrentPage(pageObject.getPageable().getPageNumber() + 1);
        pageInfo.setTotalRecord(pageObject.getTotalElements());
        pageInfo.setCurrentRecord(pageObject.getContent().size());
        pageInfo.setTotalPage(pageInfo.getTotalRecord() % pageInfo.getNumPerPage() == 0 ? pageInfo.getTotalRecord() / pageInfo.getNumPerPage() : (pageInfo.getTotalRecord() % pageInfo.getNumPerPage()) + 1);
        return pageInfo;
    }
}